#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\cashflows\digitalcmscoupon.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Cashflows {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IDigitalCmsLeg
	public ref class CDigitalCmsLeg : 
            public System::MarshalByRefObject,
            public Cephei::QL::Cashflows::IDigitalCmsLeg
	{
	protected: 
		boost::shared_ptr<QuantLib::DigitalCmsLeg>* _ppDigitalCmsLeg;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DigitalCmsLeg>* _phDigitalCmsLeg;
#endif
		Object^ _DigitalCmsLegOwner;     // reference to object that manages the storage for this object
	internal:
		CDigitalCmsLeg (Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::ISwapIndex^ index);
        CDigitalCmsLeg (boost::shared_ptr<QuantLib::DigitalCmsLeg>& childNative, Object^ owner);
        CDigitalCmsLeg (QuantLib::DigitalCmsLeg& childNative, Object^ owner);
        CDigitalCmsLeg (CDigitalCmsLeg^ copy);
        CDigitalCmsLeg (System::Type^ t);
#ifdef STRUCT
        CDigitalCmsLeg (QuantLib::DigitalCmsLeg childNative);
#endif       
#ifdef HANDLE
		CDigitalCmsLeg (QuantLib::Handle<QuantLib::DigitalCmsLeg>& childNative, Object^ owner);
		CDigitalCmsLeg (QuantLib::Handle<QuantLib::DigitalCmsLeg> childNative);
#endif
		virtual ~CDigitalCmsLeg ();
		!CDigitalCmsLeg ();

	internal:
		QuantLib::DigitalCmsLeg& GetReference ();
		boost::shared_ptr<QuantLib::DigitalCmsLeg>& GetShared ();
		QuantLib::DigitalCmsLeg* GetPointer ();
        void SetDigitalCmsLeg (boost::shared_ptr<QuantLib::DigitalCmsLeg> native)
        {
            if (_ppDigitalCmsLeg != NULL)
                delete _ppDigitalCmsLeg;
            _ppDigitalCmsLeg = new boost::shared_ptr<QuantLib::DigitalCmsLeg> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DigitalCmsLeg>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ InArrears (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithCallATM (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithCallPayoffs (Cephei::IVector<Double>^ payoffs) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithCallStrikes (Cephei::IVector<Double>^ strikes) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithFixingDays (Cephei::IVector<UInt32>^ fixingDays) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithGearings (Cephei::IVector<Double>^ gearings) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithLongCallOption (QL::Position::TypeEnum type) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithLongPutOption (QL::Position::TypeEnum type) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithNotionals (Cephei::IVector<Double>^ notionals) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithPaymentAdjustment (QL::Times::BusinessDayConventionEnum convention) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithPaymentDayCounter (Cephei::QL::Times::IDayCounter^ dayCounter) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithPutATM (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithPutPayoffs (Cephei::IVector<Double>^ payoffs) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithPutStrikes (Cephei::IVector<Double>^ strikes) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithReplication (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Cashflows::IDigitalReplication^>^ replication) ;
		virtual Cephei::QL::Cashflows::IDigitalCmsLeg^ WithSpreads (Cephei::IVector<Double>^ spreads) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CDigitalCmsLeg_Factory : public System::MarshalByRefObject,  public IDigitalCmsLeg_Factory
	{
	public:
        virtual IDigitalCmsLeg^ Create (Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::ISwapIndex^ index);
    };
   
/*Cephei*/ } /*QL*/ } /*Cashflows */}
